import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Java03 {
    public static void main(String[] args) {
     HashMap<String,Integer> map=new HashMap<>();
     countFile(new File("D:\\code\\javademo\\012Java008"),map);
     for(Map.Entry<String,Integer> entry:map.entrySet()){
         System.out.println(entry.getKey()+":"+entry.getValue()+"个");
     }
    }
    public static void countFile(File file, HashMap<String, Integer> map) {
        File[] filelist = file.listFiles();
        for (File f1 : filelist) {
            if (f1.isFile()) {
                String fileName = f1.getName();
               int n=fileName.lastIndexOf(".");
                       if(n!=-1){
                           String extension=fileName.substring(n+1);
                           if (map.containsKey(extension)){
                               map.put(extension,map.get(extension)+1);
                    }else {
                        map.put(extension,1);
                    }
                }
            } else if (f1.isDirectory()) {
                countFile(f1, map);
            }
        }
    }

}
